package com.tengju.user.domain.model.sign;

import lombok.AllArgsConstructor;

import java.util.List;

@AllArgsConstructor
public enum StarSignStatus {

    SEND_ALREADY(1, "已邀约", List.of(StarSignStepEnum.SEND_ALREADY), null),
    SURVEY_ALREADY(2, "问卷完成", List.of(StarSignStepEnum.SURVEY_ALREADY), null),
    AUDITING(3, "待审核", List.of(StarSignStepEnum.ACCOUNT_ALREADY), StarAuditStatEnum.WAIT_AUDIT),
    AUDIT_REFUSE(4, "审核拒绝", List.of(StarSignStepEnum.ACCOUNT_ALREADY), StarAuditStatEnum.DENY_AUDIT),
    AUDIT_ALREADY(5, "审核通过", List.of(StarSignStepEnum.AUDIT_ALREADY), StarAuditStatEnum.PASS_AUDIT),
    EXAM_ALREADY(6, "考试完成", List.of(StarSignStepEnum.EXAM_ALREADY), null),
    SIGN_ALREADY(7, "签约完成", List.of(StarSignStepEnum.SIGN_ALREADY, StarSignStepEnum.END), null),
    END(8, "已终止", List.of(StarSignStepEnum.TERMINATED), null),
    ;

    Integer val;
    String desc;
    List<StarSignStepEnum> step;
    StarAuditStatEnum auditStat;

    public Integer getVal() {
        return val;
    }

    public String getDesc() {
        return desc;
    }

    public List<StarSignStepEnum> getStep() {
        return step;
    }

    public StarAuditStatEnum getAuditStat() {
        return auditStat;
    }

    public static StarSignStatus fromVal(Integer val) {
        if (val == null) {
            return null;
        }
        for (StarSignStatus type : values()) {
            if (type.val.equals(val)) {
                return type;
            }
        }
        return null;
    }

    public static StarSignStatus fromStepAndAuditStat(StarSignStepEnum step, StarAuditStatEnum auditStat) {

        if (step == null) {
            return null;
        }

        for (StarSignStatus type : values()) {
            if (step != StarSignStepEnum.ACCOUNT_ALREADY && type.step.contains(step)) {
                return type;
            } else if (step == StarSignStepEnum.ACCOUNT_ALREADY && type.step.contains(step) && type.auditStat == auditStat) {
                return type;
            }
        }
        return null;
    }

}
